package 第二章数据结构.双链表.id827双链表;

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    //第几个节点
    static int cnt = 0;
    static HashMap<Integer,Node>map = new HashMap<>();
    static Node head = new Node(0,cnt);
    static Node tail = new Node(0,cnt);
    public static void main(String[]args){
        head.next = tail;
        tail.pre = head;

        //处理输入
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        scanner.nextLine();
        while ( m -- > 0){
            String s = scanner.nextLine();
            String[] ops = s.split(" ");
            String op = ops[0];
            if(op.equals("L")){
                int x = Integer.parseInt(ops[1]);
                l_insert(x);
            }else if(op.equals("R")){
                int x = Integer.parseInt(ops[1]);
                r_insert(x);
            }else if(op.equals("D")){
                int k = Integer.parseInt(ops[1]);
                delete(k);
            }else if(op.equals("IL")){
                int k = Integer.parseInt(ops[1]);
                int x = Integer.parseInt(ops[2]);
                il_insert(k,x);
            }else if(op.equals("IR")){
                int k = Integer.parseInt(ops[1]);
                int x = Integer.parseInt(ops[2]);
                ir_insert(k,x);
            }
        }
        //处理输出
        Node cur = head.next;
        while (cur != tail){
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
    }
    //左端插入数x
    static public void l_insert(int x){
        cnt++;
        Node cur = new Node(x,cnt);
        Node temp = head.next;
        head.next = cur;
        cur.next = temp;
        temp.pre = cur;
        cur.pre = head;
        map.put(cnt,cur);
    }
    //右端插入数x
    static public void r_insert(int x){
        cnt++;
        Node cur = new Node(x,cnt);
        Node temp = tail.pre;
        temp.next = cur;
        cur.next = tail;
        cur.pre = temp;
        tail.pre = cur;
        map.put(cnt,cur);
    }
    //删除第k个插入的数
    static public void delete(int k){
        Node cur = map.get(k);
        cur.next.pre = cur.pre;
        cur.pre.next = cur.next;
    }
    //第k个插入的数左侧插入
    static public void il_insert(int k, int x){
        Node cur = map.get(k);
        cnt++;
        Node node = new Node(x,cnt);
        cur.pre.next = node;
        node.next = cur;
        node.pre = cur.pre;
        cur.pre = node;
        map.put(cnt,node);
    }
    //第k个插入的数右侧插入
    static public void ir_insert(int k, int x){
        Node cur = map.get(k);
        cnt++;
        Node node = new Node(x,cnt);
        cur.next.pre = node;
        node.pre = cur;
        node.next = cur.next;
        cur.next = node;
        map.put(cnt,node);
    }
    static class Node{
        int val;
        //当前节点是第几个节点
        int cnt;
        Node pre;
        Node next;
        Node(int val, int cnt){
            this.val = val;
            this.cnt = cnt;
        }
    }
}
